#include <stdio.h>
#include <stdlib.h>

#define MAX_SIZE 10

//定义别名类型 bool_t
typedef int bool_t;

//定义类型list_t
typedef struct {
    size_t size;
    int *items;
} list_t;

//一个私有行为，检查列表是否为完整的
bool_t __list_is_full(list_t* list) {
    return (list->size == MAX_SIZE);
}

//另一个私有行为检查索引
bool_t __check_index(list_t* list, const int index) {
    return (index >= 0 && index <= list->size);
}

//为一个列表对象分配内存
list_t* list_malloc() {
    return (list_t*)malloc(sizeof(list_t));
}

//列表对象的构造函数
void list_init(list_t* list) {
    list->size = 0;
    //从堆中分配内存
    list->items = (int*)malloc(MAX_SIZE * sizeof(int));
}

//列表对象的析构函数
void list_destroy(list_t* list) {
    //释放分配的内存
    free(list->items);
}

int list_add(list_t* list, const int item) {
    //私有行为的使用
    if (__list_is_full(list)) {
        return -1;
    }
    list->items[list->size++] = item;
    return 0;
}

int list_get(list_t* list, const int index, int* result) {
    if (__check_index(list, index)) {
        *result = list->items[index];
        return 0;
    }
    return -1;
}

void list_clear(list_t* list) {
    list->size = 0;
}

size_t list_size(list_t* list) {
    return list->size;
}

void list_print(list_t* list) {
    printf("[");
    for (size_t i = 0; i < list->size; i++) {
        printf("%d", list->items[i]);
    }
    printf("]\n");
}

